package service.impl;

import dao.VehiclecomplaintsDao;
import entity.Brand;
import entity.Vehiclecomplaints;
import org.apache.ibatis.session.SqlSession;
import service.VehiclecomplaintsService;
import utils.MyBatisUtil;

import java.util.List;

/**
 * @author 吴阳基
 * @datetime 2024/01/04 14:45
 */
public class VehiclecomplaintsServiceImpl implements VehiclecomplaintsService {
    @Override
    public List<Vehiclecomplaints> VehiclecomplaintsList(Integer brandId) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(VehiclecomplaintsDao.class).VehiclecomplaintsList(brandId);
    }

    @Override
    public List<Brand> brandList() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(VehiclecomplaintsDao.class).brandList();
    }

    @Override
    public int add(Vehiclecomplaints vehiclecomplaints) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        int add = sqlSession.getMapper(VehiclecomplaintsDao.class).add(vehiclecomplaints);
        sqlSession.commit();
        return add;
    }

    @Override
    public int update(int status, int id) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();

        status = status == 0 ? 1 : 0;


        int update = sqlSession.getMapper(VehiclecomplaintsDao.class).update(status, id);
        sqlSession.commit();
        return update;
    }
}
